import { Component, OnInit } from '@angular/core';

import { MonitorBrandComponentService } from './monitor.brand.component.service';

import { BrandBase } from '../../brand/brand.base';

import { Util } from '../../../utils/util';

@Component({
  selector: 'monitor-brand',
  templateUrl: './monitor.brand.component.html',
  styleUrls: ['./monitor.brand.component.css'],
  providers: [MonitorBrandComponentService]
})
export class MonitorBrandComponent extends BrandBase {
  constructor(public service: MonitorBrandComponentService, public util: Util) {
    // 继承
    super(util, service);
    console.log(this);
    this.getHttp(this.param);
  }

  // 参数
  param: any = {
    type: 3,
    start: 0,
    rows: 1000,
    sort: '',
    sortType: ''
  };

  p: number = 0;

  // ngOnInit(){
  //   // this.util.columnHiddenHandel(this.columns,this.timeType);

  // }
  addView: boolean = false;
  add() {
    this.addView = !this.addView;

    if (this.addView == false) {
      this.getHttp(this.param);
    }
  }

  sortChange(sort) {
    console.log(sort);

    let _sort: string = sort.sort;

    let _sortType: string = sort.sortType;

    if (_sortType == 'desc') {
      this.vm.table.brands.sort((a, b) => {
        return a[_sort] < b[_sort];
      });
    } else {
      this.vm.table.brands.sort((a, b) => {
        return a[_sort] > b[_sort];
      });
    }
  }

  export() {
    let dim = [
      'date',
      'categoryName',
      'categoryId',
      'brandName',
      'sellMoney',
      'sellAmount',
      'monthSellMoney',
      'monthSellAmount',
      'productNum',
      'shopNum',
      'tsellMoney',
      'tsellAmount',
      'monthTSellMoney',
      'monthTSellAmount',
      'tproductNum',
      'tshopNum',
      'thksellMoney',
      'thksellAmount',
      'monthThkSellMoney',
      'monthThkSellAmount',
      'thkproductNum',
      'thkshopNum',
      'gsellMoney',
      'gsellAmount',
      'monthGSellMoney',
      'monthGSellAmount',
      'gproductNum',
      'gshopNum',
      'csellMoney',
      'csellAmount',
      'monthCSellMoney',
      'monthCSellAmount',
      'cproductNum',
      'cshopNum'
    ];

    let dimText = [
      '时间',
      '类目',
      '类目id',
      '品牌名',
      '日销售额',
      '日销售量',
      '近30天销售额',
      '近30天销售量',
      '宝贝数',
      '店铺数',
      '天猫日销售额',
      '天猫日销售量',
      '天猫近30天销售额',
      '天猫近30天销售量',
      '天猫宝贝数',
      '天猫店铺数',
      '天猫国际日销售额',
      '天猫国际日销售量',
      '天猫国际近30天销售额',
      '天猫国际近30天销售量',
      '天猫国际宝贝数',
      '天猫国际店铺数',
      '全球购日销售额',
      '全球购日销售量',
      '全球购近30天销售额',
      '全球购近30天销售量',
      '全球购宝贝数',
      '全球购店铺数',
      '淘宝日销售额',
      '淘宝日销售量',
      '淘宝近30天销售额',
      '淘宝近30天销售量',
      '淘宝宝贝数',
      '淘宝店铺数'
    ];

    let fileName = '全部监控品牌';

    let data = this.util.jsonToArrry(this.vm.table.brands, dim, dimText);

    this.util.export(data, fileName);
  }

  getHttp(param) {
    var res: any = {
      code: 0,
      msg: '成功',
      data: {
        value: [
          {
            id: '-1\u0001vatti/华帝',
            date: '2019-07-17 00:00:00',
            categoryId: '-1',
            categoryName: '/',
            categoryLevel: 0,
            brandName: 'vatti/华帝',
            sellAmount: 2607,
            tsellAmount: 2207,
            csellAmount: 400,
            thksellAmount: 0,
            gsellAmount: 0,
            monthSellAmount: 95072,
            monthTSellAmount: 82434,
            monthCSellAmount: 12638,
            monthThkSellAmount: 0,
            monthGSellAmount: 0,
            sellMoney: 2770979.89,
            tsellMoney: 2690002.6,
            csellMoney: 80977.29,
            thksellMoney: 0.0,
            gsellMoney: 0.0,
            monthSellMoney: 1.2131421289e8,
            monthTSellMoney: 1.1825654004e8,
            monthCSellMoney: 3057672.85,
            monthThkSellMoney: 0.0,
            monthGSellMoney: 0.0,
            productNum: 1728,
            tproductNum: 1220,
            cproductNum: 508,
            thkproductNum: 0,
            gproductNum: 0,
            shopNum: 205,
            tshopNum: 67,
            cshopNum: 138,
            thkshopNum: 0,
            gshopNum: 0
          },
          {
            id: '-1\u0001健将',
            date: '2019-07-17 00:00:00',
            categoryId: '-1',
            categoryName: '/',
            categoryLevel: 0,
            brandName: '健将',
            sellAmount: 3832,
            tsellAmount: 3133,
            csellAmount: 699,
            thksellAmount: 0,
            gsellAmount: 0,
            monthSellAmount: 127668,
            monthTSellAmount: 106127,
            monthCSellAmount: 21541,
            monthThkSellAmount: 0,
            monthGSellAmount: 0,
            sellMoney: 220741.06,
            tsellMoney: 193395.44,
            csellMoney: 27345.62,
            thksellMoney: 0.0,
            gsellMoney: 0.0,
            monthSellMoney: 7423530.39,
            monthTSellMoney: 6603732.81,
            monthCSellMoney: 819797.58,
            monthThkSellMoney: 0.0,
            monthGSellMoney: 0.0,
            productNum: 2529,
            tproductNum: 863,
            cproductNum: 1666,
            thkproductNum: 0,
            gproductNum: 0,
            shopNum: 191,
            tshopNum: 23,
            cshopNum: 168,
            thkshopNum: 0,
            gshopNum: 0
          },
          {
            id: '-1\u0001nike/耐克',
            date: '2019-07-17 00:00:00',
            categoryId: '-1',
            categoryName: '/',
            categoryLevel: 0,
            brandName: 'nike/耐克',
            sellAmount: 86586,
            tsellAmount: 29779,
            csellAmount: 55263,
            thksellAmount: 171,
            gsellAmount: 1373,
            monthSellAmount: 2542556,
            monthTSellAmount: 978663,
            monthCSellAmount: 1489430,
            monthThkSellAmount: 9625,
            monthGSellAmount: 64838,
            sellMoney: 2.417396055e7,
            tsellMoney: 9208153.64,
            csellMoney: 1.441221081e7,
            thksellMoney: 163301.98,
            gsellMoney: 390294.12,
            monthSellMoney: 6.6418174825e8,
            monthTSellMoney: 2.860427224e8,
            monthCSellMoney: 3.5579090688e8,
            monthThkSellMoney: 9610099.36,
            monthGSellMoney: 1.273801961e7,
            productNum: 103824,
            tproductNum: 21414,
            cproductNum: 77570,
            thkproductNum: 1318,
            gproductNum: 3522,
            shopNum: 6099,
            tshopNum: 116,
            cshopNum: 5588,
            thkshopNum: 16,
            gshopNum: 379
          },
          {
            id: '-1\u0001名门静音门锁',
            date: '2019-07-17 00:00:00',
            categoryId: '-1',
            categoryName: '/',
            categoryLevel: 0,
            brandName: '名门静音门锁',
            sellAmount: 3,
            tsellAmount: 0,
            csellAmount: 3,
            thksellAmount: 0,
            gsellAmount: 0,
            monthSellAmount: 564,
            monthTSellAmount: 0,
            monthCSellAmount: 564,
            monthThkSellAmount: 0,
            monthGSellAmount: 0,
            sellMoney: 635.0,
            tsellMoney: 0.0,
            csellMoney: 635.0,
            thksellMoney: 0.0,
            gsellMoney: 0.0,
            monthSellMoney: 48821.64,
            monthTSellMoney: 0.0,
            monthCSellMoney: 48821.64,
            monthThkSellMoney: 0.0,
            monthGSellMoney: 0.0,
            productNum: 17,
            tproductNum: 0,
            cproductNum: 17,
            thkproductNum: 0,
            gproductNum: 0,
            shopNum: 3,
            tshopNum: 0,
            cshopNum: 3,
            thkshopNum: 0,
            gshopNum: 0
          },
          {
            id: '-1\u0001nomad（3c数码配件）',
            date: '2019-07-17 00:00:00',
            categoryId: '-1',
            categoryName: '/',
            categoryLevel: 0,
            brandName: 'nomad（3c数码配件）',
            sellAmount: 19,
            tsellAmount: 19,
            csellAmount: 0,
            thksellAmount: 0,
            gsellAmount: 0,
            monthSellAmount: 1088,
            monthTSellAmount: 1085,
            monthCSellAmount: 1,
            monthThkSellAmount: 0,
            monthGSellAmount: 2,
            sellMoney: 3388.6,
            tsellMoney: 3388.6,
            csellMoney: 0.0,
            thksellMoney: 0.0,
            gsellMoney: 0.0,
            monthSellMoney: 197021.6,
            monthTSellMoney: 196487.6,
            monthCSellMoney: 178.0,
            monthThkSellMoney: 0.0,
            monthGSellMoney: 356.0,
            productNum: 57,
            tproductNum: 55,
            cproductNum: 1,
            thkproductNum: 0,
            gproductNum: 1,
            shopNum: 13,
            tshopNum: 11,
            cshopNum: 1,
            thkshopNum: 0,
            gshopNum: 1
          },
          {
            id: '-10081378955521\u0001创星（手机）',
            date: '2019-07-17 00:00:00',
            categoryId: '-10081378955521',
            categoryName: '数码/手机/家电',
            categoryLevel: 1,
            brandName: '创星（手机）',
            sellAmount: 1001,
            tsellAmount: 959,
            csellAmount: 42,
            thksellAmount: 0,
            gsellAmount: 0,
            monthSellAmount: 34809,
            monthTSellAmount: 31873,
            monthCSellAmount: 2936,
            monthThkSellAmount: 0,
            monthGSellAmount: 0,
            sellMoney: 109200.0,
            tsellMoney: 106153.0,
            csellMoney: 3047.0,
            thksellMoney: 0.0,
            gsellMoney: 0.0,
            monthSellMoney: 3460203.3,
            monthTSellMoney: 3069455.3,
            monthCSellMoney: 390748.0,
            monthThkSellMoney: 0.0,
            monthGSellMoney: 0.0,
            productNum: 192,
            tproductNum: 156,
            cproductNum: 36,
            thkproductNum: 0,
            gproductNum: 0,
            shopNum: 59,
            tshopNum: 34,
            cshopNum: 25,
            thkshopNum: 0,
            gshopNum: 0
          }
        ],
        count: 6
      },
      size: 0
    };

    this.vm.table.brands = res.data.value;

    this.vm.table.count = res.data.count;
  }
}
